package srjava.presenter;


import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;

import javax.swing.table.AbstractTableModel;

import srjava.messages.ServerFullInfo;

public class ServerTableModel extends AbstractTableModel {
	/**
	 * 
	 */
	private static final long serialVersionUID = 5142755965759086417L;
	ArrayList<ServerFullInfo> array = new ArrayList<ServerFullInfo>();

	@Override
	public int getColumnCount() {
		return 3;
	}

	@Override
	public int getRowCount() {
		return array.size();
	}

	@Override
	public Object getValueAt(int arg0, int arg1) {
		if (arg0 > array.size() || arg1 > 3) return null; 
		if (arg1 == 0) return array.get(arg0).getName();
		if (arg1 == 1) return array.get(arg0).getServerStatus();
		if (arg1 == 2) return array.get(arg0).getNumberOfTasks();
		return null;
	}
	
	public void setTableList(LinkedList<ServerFullInfo> list) {
		Iterator<ServerFullInfo> it = list.iterator();
		array.clear();
		while (it.hasNext()) {
			array.add(it.next());
		}
		fireTableDataChanged();
	}

}
